<?php
/**
 * @author
 */
class yueche extends admin{
   public function __construct(){
      parent::__construct();

   }

   //用户列表
   public function index(){
      $school_id = (int)$_SESSION['client']['jx_id'];
      $where = 'where school_id='.$school_id;
      $date = array();
      for ($i=0; $i<4 ; $i++) {
         $date[$i] = date('Y-m-d',NOW+3600*24*$i);
      }
      $where .= " and book_date in ('$date[0]','$date[1]','$date[2]','$date[3]')";
      $res2 = db()->getAll("select book_time,book_date from x_coach_book ".$where.' and book_kemu="2"');
      $res3 = db()->getAll("select book_time,book_date from x_coach_book ".$where.' and book_kemu="3"');
      $arr2=array();
      foreach ($res2 as $v) {
         for($i=0;$i<4;$i++){
            if(!isset($arr2[$v['book_time']][$i])) $arr2[$v['book_time']][$i]=0;
            if($v['book_date']==$date[$i]){
               $arr2[$v['book_time']][$i]++;
            }
         }
      }
      $arr3=array();
      foreach ($res3 as $v) {
         for($i=0;$i<4;$i++){
            if(!isset($arr3[$v['book_time']][$i])) $arr3[$v['book_time']][$i]=0;
            if($v['book_date']==$date[$i]){
               $arr3[$v['book_time']][$i]++;
            }
         }
      }
      $this->ajaxReturn(array('status'=>1, 'km2'=>$arr2, 'km3'=>$arr3, 'date'=>$date));

   }

   public function search(){
      $school_id = (int)$_SESSION['client']['jx_id'];
      $where = ' where school_id='.$school_id;

      $book_time = $_POST['book_time'];
      $where .= ' and book_time='.$book_time;
      $book_date = $_POST['book_date'];
      $where .= ' and book_date="'.$book_date.'"';
      $km = $_POST['km'];
      $where .= ' and book_kemu="'.$km.'"';

      $res = db()->getAll('select uid,coach_id from x_coach_book '.$where);
      foreach ($res as $k => $v) {
         $pers = db()->getRow('select real_name,mobile from x_user where id='.$v['uid']);
         $res[$k]['real_name'] = $pers['real_name'];
         $res[$k]['mobile'] = $pers['mobile'];
         $res[$k]['coach_name'] = db()->getOne('select real_name from x_user where id='.$v['coach_id']);
      }
      $this->ajaxReturn(array('status'=>1, 'data'=>$res));
   }

}
